import React, { Component } from 'react';
import { connect } from 'dva';
import { Form, Button, Select, Table, Input } from 'antd';
const { Option } = Select;

const mapStateToProps = (state) => {
    // console.log(state,'state...................')
    return state.studentmanagement
}
@connect(mapStateToProps)
class LookItem extends Component {

    state = {
        student_name: '',
        loading: true
    }

    componentDidMount () {
        this.searchBtn()
    }

    searchBtn = (payload = {}) => {
      this.setState({
        loading: true
      }, () => {
        this.props.dispatch({
          type: 'studentmanagement/SearchBtn',
          payload
        }).then(() => {
          this.setState({
            loading: false
          })
        })
      })
    }
    DeleteBtn = (payload) => {
      this.props.dispatch({
        type: 'studentmanagement/mangerstudentid',
        payload
      })
    }
    fetchSearch = () => {

    }

    get tableColumns () {
        return [{
            title: '姓名',
            dataIndex: 'student_name',
            key: 'student_name',
            render: text => <a>{text}</a>
        },
        {
            title: '学号',
            dataIndex: 'student_id',
            key: 'student_id',
        },{
            title: '班级',
            dataIndex: 'user_name',
            key: 'user_name',
        },{
            title: '教室',
            dataIndex: 'user_name',
            key: 'user_name',
        },{
            title: '密码',
            dataIndex: 'student_pwd',
            key: 'student_pwd',
        },
        {
            title: '操作',
            dataIndex: 'address',
            key: 'address',
            render: (text, record, index) => {
              return (
                <React.Fragment>
                  <a style={{ marginRight: 16 }} onClick={()=>{this.DeleteBtn(record.student_id)}}>删除</a>
                </React.Fragment>
              )
            }
          }]
    }

    render() {
        const { getmangerstudentList, mangerroomList, getmangergradeList, searchList} = this.props
        // console.log(getmangerstudentList,'getmangerstudentList..................')
        return (
            <div>
                学生管理
                <div>
                    <Form
                        layout="inline"
                        initialValues={{
                            questions_type_id: '',
                            room_id: '',
                            subject_id: ''
                        }}
                        onFinish={this.searchBtn}
                    >
                    <Form.Item name="student_name">
                        <Input placeholder="请输入学生姓名" />
                    </Form.Item>
                    <Form.Item name="room_id">
                        <Select style={{ width: 150 }}>
                            <Option value="" key={1}>全部</Option>
                            {
                                mangerroomList.map(item=><Option value={item.room_id} key={item.room_id}>{item.room_text}</Option>)
                            }
                        </Select>
                    </Form.Item>
                    <Form.Item name="subject_id">
                        <Select style={{ width: 150 }}>
                            <Option value="" key={1}>全部</Option>
                            {
                                getmangergradeList.map(item=><Option value={item.subject_id} key={item.subject_id}>{item.subject_text}</Option>)
                            }
                        </Select>
                    </Form.Item>
                    <Form.Item>
                    <Button type="primary" htmlType="submit">查询</Button>
                    </Form.Item>
                    <Form.Item>
                    <Button type="primary" htmlType="submit">重置</Button>
                    </Form.Item>
                    </Form>
                </div>
                <div className="table">
                    <Table loading={this.state.loading} columns={this.tableColumns} dataSource={ getmangerstudentList } />
                </div>
            </div>
        );
    }
}

export default LookItem;
